package com.kclm.test;

import com.kclm.pojo.Emp;
import com.kclm.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @Author : lvhx
 * @Date: 2025/10/28 10:44
 * @Description:
 */
public class MybatisTest1 {
    public static void main(String[] args) throws  Exception{

        //读取配置文件
        String resource = "mybatis-config.xml";
        // 加载配置文件
        InputStream inputStream = Resources.getResourceAsStream(resource);
        // 创建SqlSessionFactory对象
//        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSessionFactory sqlSessionFactory2 = new SqlSessionFactoryBuilder().build(inputStream,"prod");
        // 3 获取执行sql的对象  sqlSession
//        SqlSession session = sqlSessionFactory.openSession();
//        User user  = session.selectOne("com.kclm.mapper.UserMapper.selectById", 1L);
//        Emp emp = session.selectOne("a2.selectById", 1L);
//        System.out.println(user);
        SqlSession session2 = sqlSessionFactory2.openSession(true);
        System.out.println("==============");
        Object o = session2.selectOne("com.kclm.mapper.UserMapper.selectById", 1L);
        System.out.println(o);


    }
}
